package com.athuiju.hr.mapper;

import com.athuiju.hr.entity.Performance;
import com.athuiju.hr.entity.vo.PerBilityVo;
import com.athuiju.hr.entity.vo.PerIdeaVo;
import com.athuiju.hr.entity.vo.PerformanceVo;
import com.athuiju.hr.entity.vo.ProRessultVo;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author wzh
 * @since 2022-01-19
 */
@Repository
@Component
public interface PerformanceMapper extends BaseMapper<Performance> {

    /*
     * 根据员工id查询员工绩效
     * */
    @Select("SELECT\n" +
            "\t`performance`.id id,\n performance.profilesid profilesid, " +
            "\tperformance.`code`,\n" +
            "\tperformance.ego,\n" +
            "\tperformance.task,\n" +
            "\tperformance.quality,\n" +
            "\tperformance.solve,\n" +
            "\tperformance.report,\n" +
            "\tperformance.`quarter`,\n" +
            "\tperformance.teamwork,\n" +
            "\tperformance.dedicated,\n" +
            "\tperformance.serve,\n" +
            "\tperformance.hug,\n" +
            "\tperformance.year_idea,\n" +
            "\tperformance.quarter_scarce,\n" +
            "\tperformance.code+performance.ego+performance.task+performance.quality+performance.solve+performance.report AS sum_bility,\n"+
            "\tperformance.teamwork+performance.dedicated+performance.serve+performance.hug AS sum_idea,\n"+
            "\tperformance.year_scarce \n" +
            "FROM\n" +
            "\tperformance\n" +
            "\tINNER JOIN `profiles` ON performance.profilesid = `profiles`.id \n" +
            "WHERE\n" +
            "\t`profiles`.id = #{id} AND\n" +
            "\tperformance.is_deleted = 0")
    List<PerformanceVo> getByProId(String id);


    //    根据员工id查询员工工作理念绩效
@Select("SELECT\n" +
        "\tperformance.id id,performance.profilesid profilesid,\n" +
        "\tperformance.teamwork,\n" +
        "\tperformance.dedicated,\n" +
        "\tperformance.serve,\n" +
        "\tperformance.hug,\n" +
        "\tperformance.year_idea,\n" +
        "\t\tperformance.teamwork+performance.dedicated+performance.serve+performance.hug AS sum_idea,\n" +
        "\tperformance.quarter \n" +
        "\t\t\t\tFROM\n" +
        "\tperformance\n" +
        "\tINNER JOIN  profiles ON performance.profilesid = profiles.id \n" +
        "\tWHERE\n" +
        "\t`profiles`.id = #{id} AND\n" +
        "\tperformance.dedicated IS NOT NULL AND\n" +
        "\tperformance.is_deleted =0")
    List<PerIdeaVo> getPerIdeaById(String id);


    //    根据员工id查询员工工作能力绩效
@Select("SELECT\n" +
        "\tperformance.id id,performance.profilesid profilesid,performance.year_scarce, performance.code,\n" +
        "\tperformance.ego,\n" +
        "\tperformance.task,\n" +
        "\tperformance.quality,\n" +
        "\tperformance.solve,\n" +
        "\tperformance.report,\n" +
        "\tperformance.quarter_scarce,\n" +
        "\t\tperformance.code+performance.ego+performance.task+performance.quality+performance.solve+performance.report AS sum_bility\n" +
        "\tFROM\n" +
        "\tperformance\n" +
        "\tINNER JOIN  profiles ON performance.profilesid = profiles.id \n" +
        "\tWHERE\n" +
        "\t`profiles`.id = #{id} AND\n" +
        "\t performance.code IS NOT NULL AND\n" +
        "\tperformance.is_deleted =0")
    List<PerBilityVo> getPerBilityById(String id);

    //查询相同绩效工作理念信息
    @Select("SELECT * FROM performance WHERE is_deleted=0")
    List<Performance> getPerformance();



    /*
     * 删除工作能力绩效
     * */
    @Update("UPDATE performance SET `code`=NULL,year_scarce=NULL,quarter_scarce=NULL,ego=NULL,task=NULL,quality=NULL,solve=NULL,report=null WHERE performance.is_deleted=0 AND `performance`.id = #{id}")
     boolean updatePerById(String id);

    /*
     * 删除工作理念绩效
     * */
   @Update("UPDATE performance SET `teamwork`=NULL,year_idea=Null,quarter=NULL,dedicated=NULL,serve=NULL,hug=NULL WHERE performance.is_deleted=0 AND `performance`.id = #{id}")
    boolean updatePerIdeaById(String id);

    /*
     * 绩效总览分页
     * */
    List<PerformanceVo> selectMyPage(IPage<PerformanceVo> page, @Param(Constants.WRAPPER) Wrapper<PerformanceVo> querywrapper);
}
